<HTML><HEAD><TITLE>library(calendar)</TITLE></HEAD><BODY>
[ <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]<H1>library(calendar)</H1>
Routines for calendar computations, based on modified julian dates (MJD).
<H2>Predicates</H2>
<BLOCKQUOTE>
<DL>
<DT><A HREF="date_to_mjd-2.html"><STRONG>date_to_mjd(++DMY, ?MJD)</STRONG></A></DT>
<DD>Convert a date in day/month/year form to an MJD day number</DD>
<DT><A HREF="dwy_to_mjd-2.html"><STRONG>dwy_to_mjd(++DWY, ?MJD)</STRONG></A></DT>
<DD>Convert a DayOfWeek/WeekOfYear/Year representation to MJD</DD>
<DT><A HREF="dwy_to_mjd-3.html"><STRONG>dwy_to_mjd(++DWY, ++FirstWeekday, ?MJD)</STRONG></A></DT>
<DD>Convert a DayOfWeek/WeekOfYear/Year representation to MJD</DD>
<DT><A HREF="dy_to_mjd-2.html"><STRONG>dy_to_mjd(++DY, ?MJD)</STRONG></A></DT>
<DD>Convert a DayOfYear/Year representation to MJD</DD>
<DT><A HREF="jd_to_mjd-2.html"><STRONG>jd_to_mjd(++JD, ?MJD)</STRONG></A></DT>
<DD>Convert Julian Dates (JD) to Modified Julian Dates (MJD)</DD>
<DT><A HREF="mjd_now-1.html"><STRONG>mjd_now(?MJD)</STRONG></A></DT>
<DD>Returns the current date/time as (float) MJD</DD>
<DT><A HREF="mjd_to_date-2.html"><STRONG>mjd_to_date(++MJD, ?DMY)</STRONG></A></DT>
<DD>Converts an MJD day number into the corresponding Day/Month/Year</DD>
<DT><STRONG>mjd_to_dow(?, ?)</STRONG></DT>
<DD>No description available</DD>
<DT><STRONG>mjd_to_dow(?, ?, ?)</STRONG></DT>
<DD>No description available</DD>
<DT><A HREF="mjd_to_dwy-2.html"><STRONG>mjd_to_dwy(++MJD, ?DWY)</STRONG></A></DT>
<DD>Convert an MJD to a DayOfWeek/WeekOfYear/Year representation</DD>
<DT><A HREF="mjd_to_dwy-3.html"><STRONG>mjd_to_dwy(++MJD, ++FirstWeekday, ?DWY)</STRONG></A></DT>
<DD>Convert an MJD to a DayOfWeek/WeekOfYear/Year representation</DD>
<DT><A HREF="mjd_to_dy-2.html"><STRONG>mjd_to_dy(++MJD, ?DY)</STRONG></A></DT>
<DD>Convert an MJD to a DayOfYear/Year representation</DD>
<DT><A HREF="mjd_to_jd-2.html"><STRONG>mjd_to_jd(++MJD, ?JD)</STRONG></A></DT>
<DD>Convert Modified Julian Dates (MJD) to Julian Dates (JD)</DD>
<DT><A HREF="mjd_to_time-2.html"><STRONG>mjd_to_time(++MJD, ?HMS)</STRONG></A></DT>
<DD>Extracts the time in H:M:S form from a float MJD</DD>
<DT><A HREF="mjd_to_unix-2.html"><STRONG>mjd_to_unix(++MJD, ?UnixTime)</STRONG></A></DT>
<DD>Convert an MJD to the UNIX time representation</DD>
<DT><A HREF="mjd_to_weekday-2.html"><STRONG>mjd_to_weekday(++MJD, ?DayName)</STRONG></A></DT>
<DD>returns the weekday of the specified MJD as atom monday, tuesday etc</DD>
<DT><A HREF="mjd_to_ymd-2.html"><STRONG>mjd_to_ymd(++MJD, ?YMD)</STRONG></A></DT>
<DD>Converts an MJD day number into the corresponding ISO8601 Year-Month-Day form</DD>
<DT><A HREF="mjd_to_ywd-2.html"><STRONG>mjd_to_ywd(++MJD, ?YWD)</STRONG></A></DT>
<DD>Convert an MJD to ISO8601 Year-Week-Day representation</DD>
<DT><A HREF="time_to_mjd-2.html"><STRONG>time_to_mjd(++HMS, ?MJD)</STRONG></A></DT>
<DD>Convert the time in H:M:S form to a float MJD <1.0</DD>
<DT><A HREF="unix_to_mjd-2.html"><STRONG>unix_to_mjd(++UnixTime, ?MJD)</STRONG></A></DT>
<DD>Convert the UNIX time representation into a (float) MJD</DD>
<DT><A HREF="ymd_to_mjd-2.html"><STRONG>ymd_to_mjd(++YMD, ?MJD)</STRONG></A></DT>
<DD>Convert a date in ISO8601 Year-Month-Day form to an MJD day number</DD>
<DT><A HREF="ywd_to_mjd-2.html"><STRONG>ywd_to_mjd(++DWY, ?MJD)</STRONG></A></DT>
<DD>Convert an ISO8601 Year-Week-Day representation to MJD</DD>
</DL>
</BLOCKQUOTE>
<H2>Description</H2>
	Julian Dates (JD) and Modified Julian Dates (MJD) are a
	consecutive day numbering scheme widely used in astronomy,
	space travel etc. It is defined for a long period from
	12 noon, 1 Jan 4713 BC  to  12 noon, 1 Jan 3268 AD.
	<P>
	Here we use MJDs as the central representation (JDs are a bit
	awkward because they change at noon and are very large numbers).
	<P>
	Note that you can use fractional MJDs to denote the time of day.
	The time is then defined to be Universal Time (UT, formerly GMT).
	That means that every day has a unique integer number,
	or every time point has a unique float representation!
	(Using double floats, the resolution is better than 10
	microseconds until the year 2576, and better than 100
	microseconds until the year 24826).
	<P>
	Differences between times are obviously trivial to compute,
	and so are weekdays (by simple mod(7) operation).
	<P>
	The code is valid for dates starting from
		 1 Mar 0004 = MJD -677422 = JD 1722578.5
	<P>
	The relationship between JD and MJD is simply
	MJD = JD-2400000.5, ie MJD 0 = 17 Nov 1858.
<H2>Examples</H2>

What day of the week was the 29th of December 1959?
<PRE>
[eclipse 1]: lib(calendar).
[eclipse 2]: date_to_mjd(29/12/1959, MJD), mjd_to_weekday(MJD,W).
MJD = 36931
W = tuesday
</PRE>
What date and time is it now?
<PRE>
[eclipse 3]: mjd_now(MJD), mjd_to_date(MJD,Date), mjd_to_time(MJD,Time).
Date = 19 / 5 / 1999
MJD = 51317.456238425926
Time = 10 : 56 : 59.000000017695129
</PRE>
How many days are there in the 20th century?
<PRE>
[eclipse 4]: N is date_to_mjd(1/1/2001) - date_to_mjd(1/1/1901).
N = 36525
</PRE>
The library code does not detect invalid dates, but this is easily done by converting a date to its MJD and
back and checking whether they match:
<PRE>
[eclipse 5]: [user].
valid_date(Date) :-
        date_to_mjd(Date,MJD),
        mjd_to_date(MJD,Date).

[eclipse 6]: valid_date(29/2/1900). % 1900 is not a leap year!
no (more) solution.
</PRE>
<H2>About</H2><UL COMPACT>
<LI><STRONG>Author: </STRONG>Joachim Schimpf, IC-Parc
<LI><STRONG>Copyright &copy; </STRONG>Cisco Systems, Inc
<LI><STRONG>Date: </STRONG>$Date: 2009/02/19 05:38:37 $
</UL>
<HR>Generated from calendar.eci on 2009-05-27 01:25
</BODY></HTML>
